import axios from "axios"
import baseURL from './webpack-env'

// 存储当前页面url地址
localStorage.setItem('targetURL',location.href)

// 获取本地存储的token
let token = localStorage.getItem('token')

// 发送是否登录验证
// axios.get('http://localhost:8080/user/islogin',{
axios.get(baseURL + '/user/islogin',{
    headers: {
        authorization: token
    }
})
.then((res)=>{
    let data = res.data
    if (data.code === 1) {// 已登录
        $('.nickname').text(data.userInfo.nick)
    }
    else{// 未登录
        location.href = './login.html'
    }
})

// 点击 退出登录
$('.logout').on('click',function (){
    // 删除本地token
    localStorage.removeItem('token')
    // 提示用户
    alert('退出登录成功')
    // 跳转到首页
    location.href = './index.html'
})